package day17.myRelect1;

import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Properties;

/*1.	通过properties配置文件配置类的全限定名，配置方法名
         classname=xxxx
         methodname=eat
2.	通过反射在不改变源代码的情况下，执行的类中的不同方法，输出结果！
3.	升级：要求方法名称不能改，通过修改类来实现方法输出不同的内容*/
public class RelectDemo {
    public static void main(String[] args) throws ClassNotFoundException, IOException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {
        InputStream is = ClassLoader.getSystemClassLoader().getResourceAsStream("prop.properties");
        Properties prop = new Properties();
        prop.load(is);
        is.close();
        Class clazz = Class.forName(prop.getProperty("classname"));
        Constructor constructor = clazz.getConstructor();
        Object o = constructor.newInstance();
        Method method = clazz.getMethod("work");
        method.invoke(o);


    }
}
